//
//  LBExposureFilter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 4/5/13.
//  Copyright (c) 2013 UIT. All rights reserved.
//

#include "LBExposureFilter.h"
#include "LBGraphics.h"

char fShaderStrExposure[] = ""
"precision mediump float;"

"varying vec2 vtexCoor;"
"varying vec4 vposition;"
"uniform sampler2D texture;"
"uniform float exposure;"


// exposure function
"vec4 exposureColor(vec4 color, float expo){"
"   vec4 result = vec4(color.rgb * pow(2.0, expo), color.a);"
"   return result;"
"}"
// END exposure function


"void main()"
"{"
"    lowp vec4 textureColor = texture2D(texture, vtexCoor);"
"    textureColor = exposureColor(textureColor, exposure);"
"    gl_FragColor = textureColor;"
"}";

LBExposureFilter::LBExposureFilter(){
    init(0, fShaderStrExposure);
    LBGraphics::getInstance()->useProgram(program);
    exposureUniform = program->uniformIndex("exposure");
    setExposure(1.0f);
}

void LBExposureFilter::setExposure(float exposure){
    this->exposure = exposure;
    LBGraphics::getInstance()->useProgram(program);
    glUniform1f(exposureUniform, exposure);
}